function showVehicleGroupSearch(){
	window.location.href="showVehicleGroupSearch.do";
}

function ajaxFindVehicleGroupSearchList(currentPage,pageSize) {
	$.ajax({
		type:"post",
		url: "ajaxVehicleGroupSearchList.do",
		data:{
			groupname:$("#txtVGroupName").val(),
			currentPage:currentPage,
			pageSize:pageSize,
			orderBy:"id",
		},
		success:function(msg){
			$("#listVehicleGroupBox").html(msg);
		}
	});
}

function ajaxShowVehicleGroupEdit(id){
	$.ajax({
		type:"post",
		url:"ajaxShowVehicleGroupEdit.do",
		data:{id:id},
		success:function(msg){
			$("#dialog2").html(msg);
			$("#dialog2").dialog({
				autoOpen: true,
				width: 800,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons : [{
					text : "保存",
					click : function() {
						ajaxSaveVehicleGroup(this);
					}
				}, {
					text : "关闭",
					click : function() {
						$(this).dialog("close");
					}
				}]
			});
		}
	});
}

function ajaxSaveVehicleGroup(objDialog) {
	vehicleGroupValidate();
	if ($("#frmVehicleGroup").valid()) {
		$(objDialog).dialog("close");
		var options ={
				type: "post",
				url : "ajaxSaveVehicleGroup.do",
				success: function () {
					clearInput("#sltVehicleGroup");
					ajaxFindVehicleGroupSearchList(1);
					showMessageDialog("保存机动车分组","机动车分组信息保存成功。",null,dialogType.info);
				}
		};
		var i = 0;
		$("#vehicleDialog tbody input[type='hidden']").each(
				function () {$(this).attr("name","illegalVehicleInfoList["+ i++ +"].id");}
		);
		$("#frmVehicleGroup").ajaxSubmit(options);
	}
}

function ajaxShowVehicleGroupView(id){
	$.ajax({
		type:"post",
		url:"ajaxShowVehicleGroupView.do",
		data:{id:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 800,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons : [ {
					text : "关闭",
					click : function() {
						$(this).dialog("close");
					}
				} ]
			});
		}
	});
}

function ajaxDeleteVehicleGroupById(id) {
	var vehicleGroupIds="";
	var sltVG = $("#listVehicleGroupList tbody input:checked").length;
	if(id==null){
		$("#listVehicleGroupList tbody input:checked").each(function(){ 
			vehicleGroupIds += $(this).val()+";";
		});
		if (vehicleGroupIds == ""){
			showMessageDialog("提示","请选择一行或多行",null,dialogType.info);
			return;
		}else{
			vehicleGroupIds=vehicleGroupIds.substring(0, vehicleGroupIds.length-1);
		}
	}else{
		vehicleGroupIds=id;
		sltVG = 1;
	}
	if (vehicleGroupIds!=null) {
		showMessageDialog("删除机动车","确定要删除所选“"+sltVG+"”条机动车记录吗？",
				function () {
			$.ajax({					
				type:"post",
				url:"ajaxDeleteVehicleGroupByIds.do",
				data:{vehicleGroupIds:vehicleGroupIds},
				success:function(msg){
					ajaxFindVehicleGroupSearchList();
					showMessageDialog("提示","机动车分组删除成功",null,dialogType.info);
				}
			});}
		,dialogType.warning);
	} 
}

function useNatureDialogView(){
	$("#useNatureDialogView").dialog({
		autoOpen: true,
		width: 650,
		modal: true,
		buttons : [ {
			text : "关闭",
			click : function() {
				$(this).dialog("close");
			}
		} ]
	});
}

function vehicleClassificationDialogView(){
	$("#vehicleClassificationDialogView").dialog({
		autoOpen: true,
		width: 650,
		modal: true,
		buttons : [ {
			text : "关闭",
			click : function() {
				$(this).dialog("close");
			}
		} ]
	});
}

function licensePlateDialogView(){
	$("#licensePlateDialogView").dialog({
		autoOpen: true,
		width: 650,
		modal: true,
		buttons : [ {
			text : "关闭",
			click : function() {
				$(this).dialog("close");
			}
		} ]
	});
}

function vehicleTypeDialogView(){
	$("#vehicleTypeDialogView").dialog({
		autoOpen: true,
		width: 650,
		modal: true,
		buttons : [ {
			text : "关闭",
			click : function() {
				$(this).dialog("close");
			}
		} ]
	});
}

function vehicleDialogView(){
	$("#vehicleDialogView").dialog({
		autoOpen: true,
		width: 650,
		modal: true,
		buttons : [ {
			text : "关闭",
			click : function() {
				$(this).dialog("close");
			}
		} ]
	});
}

function getDialogRightForString(rightId,hiddenInputId) {
	var value="";
	var tmp="";
	$('#'+rightId+' tbody tr').each(function(){
		tmp = $(this).attr('id');
		value+=tmp.substring(6, tmp.length)+",";
	});
	value=value.substring(0,value.length-1);
	$("#" +hiddenInputId).val(value);
}

function vehicleGroupValidate(){
	$("#frmVehicleGroup").validate({
		errorLabelContainer: $("#infoVehicleGroup"),
		ignore: "",
		rules : {
			groupname : {
				required :true				
			},
			grouppriority : {
				required :true
			},
			platetypes : {
				required :true
			},
			vehicletypes : {
				required :true
			},
			vehicleclassifications : {
				required :true
			},
			vehicleusingcharacters : {
				required :true
			}
		},
		messages : {
			groupname : {
				required :"请输入机动车分组名称！"
			},
			grouppriority : {
				required :"请输入优先级！"
			},
			platetypes : {
				required :"请输入号牌种类！"
			},
			vehicletypes : {
				required :"请输入车辆类型！"
			},
			vehicleclassifications : {
				required :"请输入车辆分类！"
			},
			vehicleusingcharacters : {
				required :"请输入使用性质！"
			}
		},
		success: function(label) {
			label.html("&nbsp;");
		}
	});
}